//
//  STCollectService.swift
//  Story
//
//  Created by 汤泽川 on 2019/5/4.
//  Copyright © 2019 汤泽川. All rights reserved.
//

import Foundation
class STCollectService {
    @discardableResult
    public func queryCollectState(storyId : Int) -> STResponse<Bool> {
        let response = STResponse<Bool>()
        STCollectApi.queryCollectState(storyId: storyId) { (data, error) in
            let result : Bool?
            if data != nil {
                let x = data!.data!["state"]
                if let x = x {
                    result = (x == 1)
                } else {
                    result = false
                }
            } else {
                result = false
            }
            response.execute(result, error)
        }
        return response
    }
    
    @discardableResult
    public func changeCollectState(storyId : Int, state : Bool) -> STResponse<String> {
        let response = STResponse<String>()
        STCollectApi.changeCollectState(storyId: storyId, state: state, result: { (error) in
            response.execute(nil, error)
        })
        return response
    }
    
    public func fetchCollectStorys(page : Int, count : Int) -> STResponse<ResponseModel<[STStoryInfo]> > {
        let response = STResponse<ResponseModel<[STStoryInfo]> >()
        STCollectApi.quaryCollectStorys(page: page, count: count) { (data, error) in
            response.execute(data, error)
        }
        return response
    }
}
